<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
    <style>
        .nav {
            margin-left: 0;
        }

        .nav > li > a:focus, .nav > li > a:hover {
            text-decoration: none;
            background-color: #33CCFF !important;
        }

        .modal-dialog {
            z-index: 9999999;
        }

        @media (min-width: 768px) {
            .modal-content {
                -webkit-box-shadow: 0 5px 15px rgba(0, 0, 0, .5);
                box-shadow: 0 -2px 20px rgba(0, 0, 0, .5) !important;
            }
        }

        #userScoreTab tr th {
            background: #337ab7;
            color: #fff;
            text-align: center;
            padding: 5px 30px;
            border: 1px solid #ccc;
        }

        #userScoreTab tr td {
            padding: 5px;
            text-align: center;
            border: 1px solid #ccc;
        }
    </style>
</head>
<body class="bgcolor">
<!-- /section:basics/navbar.layout -->
<table></table>
<div class="main-container" id="main-container">


    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <div class="pull-left">

                            <button class="btn btn-sm btn-info" id="query">条件搜索</button>
                            <button class="btn btn-sm btn-success" id="exportTable">导出报表</button>
                            <button class="btn btn-sm btn-default" id="downLoad">下载评分标准</button>
                            <button class="btn btn-sm btn-danger" id="delete" style="display: none;">删除</button>
                            <%--<shiro:hasPermission name="modules:sys:dept:excel">
                                <button class="btn btn-sm btn-pink" id="export">导出</button>
                            </shiro:hasPermission>--%>
                        </div>
                        <div class="pull-right">
                            <button class="btn btn-sm btn-danger" id="gradepoint">考核记录</button>
                            <button class="btn btn-sm btn-danger" id="showSummary">考核汇总</button>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <table id="gridTable"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager"></div>
                        <!-- 查询对话框 -->
                        <div style="display: none;">
                            <div class="row" id="queryDialog"></div>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
            <div class="page-content" id="userScoreDiv">
                <h3 style="font-weight: 600;margin-top: 0px;">最新绩效得分:</h3>
                <div id="yhdf"></div>
                <%--<table border="1" id="userScoreTab">
                    <tr>
                        <th>用户名</th>
                        <th>最终得分</th>
                        <th>绩效得分</th>
                        <th>组别</th>
                        <th>组内排名</th>
                    </tr>
                    <tr>
                        <td>${user.name}</td>
                        <td>${finalScore == null ? "--" : finalScore}</td>
                        <td>${finalRank == null ? "--" : finalRank}</td>
                        <td>${user.branch}</td>
                        <td>${itemRank == null ? "--" : itemRank}</td>
                    </tr>
                </table>--%>
            </div>
        </div>


    </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>


</div><!-- /.main-container -->
</div>
<!-- footer -->
<script src="<s:url value="/assets/web/common/bootstrapvalidator/dist/js/bootstrapValidator.js"></s:url>"></script>
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<!-- dialog -->
<%@ include file="/WEB-INF/views/include/dialog.jsp" %>


<script type="text/javascript">
    //基本路径
    var baseUrl = "<s:url value="/gradepoint"></s:url>/"
    //jqgrid的表格高度
    var height = 320;
    //jqgrid表格行头的中文
    var colNames = ['', '分数', '排名', '生成日期', '考核类别', '考核对象', '考核任务名', '考核任务单号', '考核内容', '考核更新时间'];
    var colModel = [

        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'soucre', index: 'soucre', width: 50, editable: true, cellattr: addCellAttr},
        {name: 'rank', index: 'rank', width: 40, editable: true, cellattr: addCellAttr},
        {name: 'createDate', index: 'createDate', width: 100, editable: true},
        {name: 'checkType', index: 'checkType', width: 130, editable: true},
        {name: 'checkObject', index: 'checkObject', width: 100, editable: true},
        {name: 'taskName', index: 'taskName', width: 545, editable: true},
        {name: 'taskId', index: 'taskId', width: 190, editable: true},
        {name: 'taskContent', index: 'taskContent', width: 500, editable: true},
        {name: 'updDate', index: 'updDate', width: 100, editable: true}
    ];

    //jqgrid的具体执行方法
    jqgrid({
        autoScroll: false,
        shrinkToFit: false,
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",
        onSelectRow: function (rowid, status) {
            rowids = $('#gridTable').jqGrid('getGridParam', 'selarrrow');
        },
        onSelectAll: function (aRowids, status) {
            rowids = $('#gridTable').jqGrid('getGridParam', 'selarrrow');
        },
        gridComplete: function () {
            var rowIds = jQuery("#gridTable").jqGrid('getDataIDs');
            for (var k = 0; k < rowIds.length; k++) {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowIds[k]) {
                        flag = true;
                        continue;
                    }
                }
                if (flag && flag == true) {
                    jQuery("#gridTable").setSelection(rowIds[k], true);
                }
            }
        }
    });

    var rowids = [];//选中行id

    /**
     * 重写Array
     */
    Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };

    /**
     * 重写Array
     */
    Array.prototype.indexOf = function (val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        }
        return -1;
    };

    //加载查询对话框
    $("#queryDialog").load(getUrl("filter"));

    //重置表单
    function reset() {
        resetForm("#formDialog form");
    }

    /**
     * 导出表头选择
     */
    $("#exportTable").click(function () {
        loadDialog({
            dialogTitle: '导出绩效列表',
            dialogUrl: getUrl("formHead"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="exports()">确认</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });
    
    $("#downLoad").click(function () {
        var url = "/gradepoint/download/gqXq82aIwmBSKcBR";
        console.log(url);
        window.open(url);
    })


    function exports() {
        var formHeads = $('#formDialogBody #formHeads').serialize();   //钩选表头数据
        // if (rowids.length == 0 || exportData == "") {
        //     alert("请先勾选要导出的项目或表头");
        //     return;
        // }
        var win = confirm("确认导出？");
        if (win == true) {
            var url = "/export/exportGradePointDetail?" + formHeads + "&" + exportData + "&sysIds=" + rowids;
            console.log(url);
            window.open(url);
        }
    }

    var exportData;
    //显示查询对话框
    var queryDialog = $("#queryDialog");
    $("#query").click(function () {
        showDialog({
            dialogTitle: '查询对话框',
            dialogBody: queryDialog,
            dialogFoot: "<button type='button' class='btn btn-primary' onclick='query()'>查询</button>" +
                "<button type='button' class='btn btn-pink' onclick='reset()'>重置</button>" +
                "<button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>"
        });
    });

    //具体查询方法
    function query() {

        exportData = $('#formDialogBody #gradePointFilter').serialize();
        seachJqgird("#gridTable", "#formDialog form");
        $("#formDialog").modal('hide');
    }

    //更新操作
    $("#edits").click(function () {
        showEditView();
    });

    //考核汇总
    $("#showSummary").click(function () {
        window.location.href = '/scoresummary';
    });

    //考核记录
    $("#gradepoint").click(function () {
        window.location.href = '/gradepoint';
    });

    //催办操作
    $("#createLog").click(function () {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "更新对话框",
            dialogUrl: getUrl("createTaskLog"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="edit()" id="updatebtn" >更新</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    });

    //执行更新操作
    function edit() {
        console.log("更新操作")
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("edit"),
            tableId: "#gridTable",
            successMessage: "操作成功",
            successTitle: '操作对话框',
            //failMessage: '更新失败',
            failTitle: '消息对话框'
        });
    }

    //显示编辑对话框
    function showEditView() {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "更新对话框",
            dialogUrl: getUrl("edit"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="edit()" id="updatebtn" >更新</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    }

    //双击显示对话框
    function showView() {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "绩效详情",
            dialogUrl: getUrl("showDetail"),
            dialogFoot: '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    }


    //删除
    $("#delete").click(function () {
        showDeleteView();
    });

    //显示删除对话框
    function showDeleteView() {
        showDeleteDialog({
            url: getUrl("delete"),
            tableId: "#gridTable",
            confirmTitle: "确认对话框",
            confirmMessage: "是否确定删除?",
            confirmOk: "确定",
            confirmCancel: "取消",
            successMessage: "删除成功",
            successTitle: "消息对话框",
            failMessage: "删除失败",
            failTitle: "消息对话框",
            errorTitle: "警告提示框",
            errorMessage: "您当前尚未选中一行，请选择后再试",
            errorOk: "确定"
        });
    }

    //显示创建对话框
    $("#create").click(function () {
        loadDialog({
            dialogTitle: '创建对话框',
            dialogUrl: getUrl("create"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()">提交审核</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    //分类编辑框
    $("#createCla").click(function () {
        loadDialog({
            dialogTitle: '创建对话框',
            dialogUrl: getUrl("createCla"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()">添加</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    //保存数据
    function create() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("create"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            //failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }

    $("#gridTable").dblclick(function (e) {
        showView();
    });

    // function aa10Fmatter(cellvalue, options, rowObject) {
    //     if (cellvalue == "1") {
    //         return "有效任务";
    //     } else if (cellvalue == "0") {
    //         return "失效任务";
    //     }
    // }

    jQuery("#gridTable").jqGrid('setLabel', 0, '序号', 'labelstyle');

    $(function () {
        var branchType = '${user.branchType}';
        if (branchType == '2') {
            $("#userScoreDiv").css('display', 'none');//隐藏
        }else{
            $.ajax({
                type: "GET",
                url: "/gradepoint/getScoreAndRank",
                dataType: "json",
                data: {},
                success: function (model) {
                    var tableContent = " ";
                    if (model.code == "200") {

                        tableContent += '<table border="1" id = "userScoreTab">\n' +
                            '                    <tr>\n' +
                            '                        <th>用户名</th>\n' +
                            '                        <th>绩效得分</th>\n' +
                            // '                        <th>系统排名</th>\n' +
                            '                        <th>考核组别</th>\n' +
                            '                        <th>责任单位</th>\n' +
                            '                        <th>组内排名</th>\n' +
                            '                    </tr>';
                        tableContent += '<tr>\n' +
                            '                    <td>' + model.data.name + '</td>\n' +
                            '                    <td>' + model.data.finalScore + '</td>\n' +
                            // '                    <td>' + model.data.finalRank + '</td>\n' +
                            '                    <td>' + model.data.branchType + '</td>\n' +
                            '                    <td>' + model.data.branch + '</td>\n' +
                            '                    <td>' + model.data.itemRank + '</td>\n' +
                            '                    </tr>' +
                            '</table>';

                        //将拼接的页面放入列表里面
                        $("#yhdf").html(tableContent);
                    }
                },
                error: function (model) {
                }
            });
        }

    })

    /**
     * 给表格字体添加样式
     * @param rowId
     * @param val
     * @param rawObject
     * @param cm
     * @param rdata
     * @returns {string}
     */
    function addCellAttr(rowId, val, rawObject, cm, rdata) {
        return "style='color:red;font-weight:800;'";
    }
</script>

</body>
</html>